package com.gulimall.order.app;

import java.util.Arrays;
import java.util.Map;

import com.gulimall.order.service.impl.OrderItemServiceImpl;
import com.gulimall.order.service.impl.OrderServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gulimall.order.entity.OrderEntity;
import com.gulimall.order.service.OrderService;
import com.common.utils.PageUtils;
import com.common.utils.R;

import javax.annotation.Resource;


/**
 * 订单
 *
 * @author Rookie-886
 * @email ${email}
 * @date 2021-03-14 22:36:08
 */
@Slf4j
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Resource
    private OrderServiceImpl orderServiceImpl;
    @Resource
    private OrderItemServiceImpl orderItemServiceImpl;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("order:order:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderServiceImpl.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 查询状态
     */
    @RequestMapping("/status/{id}")
    public R getStatus(@PathVariable("id") Long id){
        OrderEntity order = orderServiceImpl.getById(id);
        return R.ok().put("order", order);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("order:order:info")
    public R info(@PathVariable("id") Long id){
		OrderEntity order = orderServiceImpl.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 获取订单分页数据（包括订单项数据）
     * @param requestParam
     * @return
     */
    @PostMapping("/getItemList")
    public R getItemList(@RequestBody Map<String,Object> requestParam){
        PageUtils page = orderItemServiceImpl.getItemList(requestParam);
        return R.ok().put("page",page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("order:order:save")
    public R save(@RequestBody OrderEntity order){
        orderServiceImpl.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("order:order:update")
    public R update(@RequestBody OrderEntity order){
        orderServiceImpl.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("order:order:delete")
    public R delete(@RequestBody Long[] ids){
        orderServiceImpl.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
